package com.chrray.position.controller.web;

import com.baomidou.mybatisplus.extension.api.R;
import com.chrray.position.domain.FdJobPostings;
import com.chrray.position.domain.FdUser;
import com.chrray.position.domain.SysArea;
import com.chrray.position.domain.dto.DictionaryDTO;
import com.chrray.position.domain.dto.FdJobPostingsDTO;
import com.chrray.position.entity.position.FdJobPostingsExe;
import com.chrray.position.entity.position.FdUserExe;
import com.chrray.position.enums.app.FdJobCheckStateEnum;
import com.chrray.position.enums.app.FdJobStateEnum;
import com.chrray.position.pojo.dto.BaseIdDto;
import com.chrray.position.pojo.response.UploadDeviceVO;
import com.chrray.position.service.web.WFdJobPostingsService;
import com.chrray.position.service.web.WFdUserService;
import com.chrray.position.util.result.PageBean;
import com.chrray.position.util.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

import static com.chrray.position.util.result.ResponseResults.PAGE;
import static com.chrray.position.util.result.ResponseResults.success;

/**
 * 业务系统用户控制器
 *
 * @author lm
 * @since 1.0.1 2024-09-02
 */
@RestController
@RequestMapping("/api/web/postings")
@Api(tags = "职位管理")
@AllArgsConstructor
public class WFdJobPostingsController {
    @Autowired
    private WFdJobPostingsService wFdJobPostingsService;


    @PostMapping("/pageList")
    @ApiOperation("列表")
    public ResponseResult<PageBean<FdJobPostings>> pageList(@RequestBody  FdJobPostingsExe fdUser) {
        return PAGE(wFdJobPostingsService.pageList(fdUser));
    }


    @GetMapping("/selectById")
    @ApiOperation("查询详情")
    @ApiResponses({
            @ApiResponse(code=200, message = "ok", response = FdJobPostings.class)
    })
    public ResponseResult<FdJobPostings> selectById(BaseIdDto dto){
        return  wFdJobPostingsService.selectById(dto.getId());
    }


    @GetMapping("/deletedById")
    @ApiOperation("删除")
    public ResponseResult<Object> deletedById(BaseIdDto dto){
        return  success(wFdJobPostingsService.removeById(dto.getId()));
    }

    @PostMapping("/publish")
    @ApiOperation("发布职位")
    public ResponseResult<Object> publishJob(@RequestBody FdJobPostings job){

        wFdJobPostingsService.publishJob(job);
        return success("发布成功");
    }

    @PostMapping("/update")
    @ApiOperation("编辑")
    public ResponseResult<Object> update(@RequestBody FdJobPostings job){

        wFdJobPostingsService.update(job);
        return success("发布成功");
    }


    @GetMapping("/down")
    @ApiOperation("下架")
    public ResponseResult<Object> down(BaseIdDto dto){
        FdJobPostings fdJobPostings=new FdJobPostings();
        fdJobPostings.setId(dto.getId());
        fdJobPostings.setStatus(FdJobStateEnum.OFF_SHELF.getValue());
        return  success(wFdJobPostingsService.updateById(fdJobPostings));
    }
    @GetMapping("/up")
    @ApiOperation("上架")
    public ResponseResult<Object> up(BaseIdDto dto){
        FdJobPostings fdJobPostings=new FdJobPostings();
        fdJobPostings.setId(dto.getId());
        fdJobPostings.setStatus(FdJobStateEnum.PENDING.getValue());
        return  success(wFdJobPostingsService.updateById(fdJobPostings));
    }
    @GetMapping("/district-selection")
    @ApiOperation("省/市/区/街道下拉选")
    public ResponseResult<List<SysArea>> districtSelection(@RequestParam("code") Long code) {
        return wFdJobPostingsService.districtSelection(code);
    }


    @ApiOperation( "导入")
    @PostMapping(value = "/importJobPostings")
    public ResponseResult<UploadDeviceVO> importJobPostings(@RequestParam(value = "file") MultipartFile file) {

        return wFdJobPostingsService.importAdjective(file);
    }
}
